package com.hlhj.funlike_businessqzxd.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.mymvp.mvp.BaseModule;
import com.example.mymvp.mvp.BasePresenter;
import com.example.mymvp.mvp.BaseView;
import com.example.mymvp.okrx.BaseBean;
import com.google.gson.Gson;
import com.hlhj.funlike_businessqzxd.R;
import com.hlhj.funlike_businessqzxd.constant.Constants;
import com.hlhj.funlike_businessqzxd.data.SPUser;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

public class StartPriceAty extends BaseActivity<BaseView, BasePresenter<BaseModule,BaseView>> implements BaseView {

    private TextView tvTitle;
    private EditText etNum;
    private TextView btCommit;
    private View btExit;

    @Override
    public void initView() {
        tvTitle = ((TextView) findViewById(R.id.tv_title));
        etNum = ((EditText) findViewById(R.id.edit_name));
        btCommit = ((TextView) findViewById(R.id.btn_ok));
        btExit = findViewById(R.id.img_back);

        tvTitle.setText("最低消费");

        etNum.setText(getIntent().getStringExtra("tv"));
    }

    @Override
    public void logicStart() {

    }

    @Override
    public void setListener() {
        btExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OkGo.<String>post(Constants.EditTakeMoney)
                        .headers("token", SPUser.getUser(getApplication()).getToken())
                        .params("start_price",etNum.getText().toString())
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                String body = response.body();
                                BaseBean bean = new Gson().fromJson(body, BaseBean.class);
                                if (bean.getCode()==1){
                                    Toast.makeText(StartPriceAty.this,"修改成功",Toast.LENGTH_SHORT).show();
                                    EventBus.getDefault().postSticky("");
                                    finish();
                                }else{
                                    Toast.makeText(StartPriceAty.this,"修改失败",Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
            }
        });
    }

    @Override
    protected int getContentId() {
        return R.layout.aty_startprice;
    }

    @Override
    protected void initData() {

    }

    @NotNull
    @Override
    public BaseView bindView() {
        return this;
    }

    @NotNull
    @Override
    public BasePresenter<BaseModule, BaseView> createPresenter() {
        return new BasePresenter<BaseModule, BaseView>() {
            @Override
            public void createModule() {

            }
        };
    }
}
